package com.handler;


import java.util.Iterator;

import utl.mofen.objects.JSonStream;

import io.netty.channel.Channel;
import io.netty.channel.group.DefaultChannelGroup;

import com.google.gson.JsonObject;
import com.netty.handler.JSonStreamNettyHandler;
import com.netty.server.console.NettyChannels;

public class BroadcastHandler extends JSonStreamNettyHandler {
	public void doAction() throws Exception {
		JsonObject jsonObject = this.jsonStream.getJSonObject();
		
		JSonStream msg = new JSonStream();
		msg.initialize();
		msg.getJSonObject().add("msg", jsonObject.get("msg"));
		
		
		//像其他通道进行广播
		DefaultChannelGroup channels = NettyChannels.getChannels();
		Iterator<Channel> it = channels.iterator();
		while (it.hasNext())
		{
			Channel channel  = it.next();
			if (channel !=ctx.channel())
			{
				channel.write(msg);
			}
		};
	}
}
